#@HplusLayout()
#define css()
<style>
	.table > tbody > tr > td, 
	.table > tbody > tr > th, 
	.table > tfoot > tr > td,
	.table > tfoot > tr > th, 
	.table > thead > tr > td, 
	.table > thead > tr > th{padding: 2px;}
	.form-control, .single-line {font-size: 12px;padding: 2px}
</style>
#end
#define content()
<div style="padding: 15px">
	<form method="post" class="form-horizontal required-validate" action="saveModel" novalidate="novalidate" onsubmit="return validateCallback(this,listDialogAjaxDone)">
		<input type="hidden" name="autocodeModel.id" value="#(autocodeModel.id)"/>
		<input type="hidden" name="autocodeModel.component_id" value="#(autocodeModel.component_id)"/>
		<div class="form-group">
	  	<label class="col-xs-2 control-label">Model名称：</label>
	    <div class="col-xs-2">
	      <input type="text" class="form-control required" placeholder="输入Model名称" name="autocodeModel.name" value="#(autocodeModel.name)"/>
	    </div>                                                              
	  	<label class="col-xs-2 control-label">Model代码：</label>
	    <div class="col-xs-2">
	      <input type="text" class="form-control required" placeholder="输入Model代码" name="autocodeModel.code" value="#(autocodeModel.code)"/>
	    </div>
	  	<label class="col-xs-2 control-label">子Model：</label>
	    <div class="col-xs-2">
	      <select name="autocodeModel.child_model" class="form-control">
	      	<option value="">无</option>
	      	#for(item:modelList)
	      		<option value="#(item.id)" #if(autocodeModel.child_model==item.id)selected="selected"#end>#(item.name)(#(item.code))</option>
	      	#end
	      </select>
	    </div>
	  </div>
	  <div class="form-group">
	  	<label class="col-xs-2 control-label">父Model：</label>
	    <div class="col-xs-2">
	      <select name="autocodeModel.parent_model" class="form-control">
	      	<option value="">无</option>
	      	#for(item:modelList)
	      		<option value="#(item.id)" #if(autocodeModel.parent_model==item.id)selected="selected"#end>#(item.name)(#(item.code))</option>
	      	#end
	      </select>
	    </div>
	  	<label class="col-xs-2 control-label">列表模式：</label>
	    <div class="col-xs-2">
	      <select name="autocodeModel.list_type" class="form-control">
	      	#(data("DEVELOP_AUTOCODE_MODEL_LISTTYPE","option",autocodeModel.list_type??""));
	      </select>
	    </div>
	  	<label class="col-xs-2 control-label">是否导出：</label>
	    <div class="col-xs-2">
	      <select name="autocodeModel.is_export" class="form-control">
	      	#(data("SHIFOU","option",autocodeModel.is_export??"F"));
	      </select>
	    </div>
	  </div>
	  <div class="form-group">
	  	<label class="col-xs-2 control-label">数据表：</label>
	    <div class="col-xs-2">
	      <input type="text" class="form-control" placeholder="选填" name="autocodeModel.tablename" value="#(autocodeModel.tablename)"/>
	    </div>      
	  	<label class="col-xs-2 control-label">操作按钮：</label>
			<div class="col-xs-4">
				<a class="btn btn-primary" onclick="loadTable()">加载字段</a>
				<a class="btn btn-primary" onclick="addPrependColumn()">开始新增字段</a>
				<a class="btn btn-primary" onclick="addAppendColumn()">结尾新增字段</a>
			</div>
	  </div>
		<table class="table">
			<thead>
				<tr>
					<td>名称</td>
					<td>字段</td>
					<td>控件类型</td>
					<td>字典编码</td>
					<td>搜索类型</td>
					<td>重复提示</td>
					<td>不能为空？</td>
					<td>默认值</td>
					<td>操作</td>
				</tr>
			</thead>
			<tbody id="column_box">
				#for(item:columnList)
				<tr class="column_div">
					<td><input type="text" class="form-control" name="columnName" style="width:80px" value="#(item.name)"/></td>
					<td><input type="text" class="form-control" name="columnColumn" style="width:80px" value="#(item.column)"/></td>
					<td>
						<select name="inputType" class="form-control" style="width:100px">
							#(data('DEVELOP_AUTOCODE_COLUMN_INPUTTYPE','option',item.inputType))
						</select>
					</td>
					<td>
						<select name="change" class="form-control" style="width:100px">
							<option value="">不使用</option>
							#for(basedata:basedataList)
								<option value="#(basedata)" #if(item.change??&&item.change==basedata)selected="selected"#end>#(basedata)</option>
							#end
						</select>
					<td>
						<select name="search" class="form-control" style="width:80px">
							<option value="">无</option>
							#(data("DEVELOP_AUTOCODE_COLUMN_SEARCH","option",item.search??""))
						</select>
					</td>
					<td><input type="text" class="form-control" name="repeat" style="width:80px" value="#(item.repeat)"/></td>
					<td>
						<select name="required" class="form-control" style="width:60px">
							#(data('SHIFOU','option',item.required??"T"))
						</select>
					</td>
					<td><input type="text" class="form-control" name="default" style="width:80px" value="#(item.default)"/></td>
					<td><a href="javascript:;" onClick="addBeforeColumn(this)">上增</a>&nbsp;&nbsp;
					<a href="javascript:;" onClick="removeColumn(this)">删</a>&nbsp;&nbsp;
					<a href="javascript:;" onClick="addAfterColumn(this)">下增</a></td>
				</tr>
				#end
			</tbody>
		</table>
    <div class="form-group">
    	<div class="col-xs-8 col-xs-offset-2">
      	<button type="submit" class="btn btn-primary">保存</button>
      </div>
    </div>
	</form>
</div>
<script id="columnTpl" type="text/html">
	<tr class="column_div">
		<td><input type="text" class="form-control" name="columnName" style="width:80px"/></td>
		<td><input type="text" class="form-control" name="columnColumn" style="width:80px" value="{{if item}}{{item.columnColumn}}{{/if}}"/></td>
		<td>
			<select name="inputType" class="form-control" style="width:100px">
				#for(item:data('DEVELOP_AUTOCODE_COLUMN_INPUTTYPE'))
					<option value="#(item.key)" {{if item}}{{if item.inputType=='#(item.key)'}}selected="selected"{{/if}}{{/if}}>#(item.value.name)</option>
				#end
			</select>
		</td>
		<td>
						<select name="change" class="form-control" style="width:100px">
							<option value="">不使用</option>
							#for(basedata:basedataList)
								<option value="#(basedata)">#(basedata)</option>
							#end
						</select>
		</td>
		<td>
			<select name="search" class="form-control" style="width:80px">
				<option value="">无</option>
				#(data('DEVELOP_AUTOCODE_COLUMN_SEARCH','option','{{item.COLUMN_NAME}}'))
			</select>
		</td>
		<td><input type="text" class="form-control" name="repeat" style="width:80px"/></td>
		<td>
			<select name="required" class="form-control" style="width:60px">
				#(data('SHIFOU','option','T'))
			</select>
		</td>
		<td><input type="text" class="form-control" name="default" style="width:80px"/></td>
		<td><a href="javascript:;" onClick="addBeforeColumn(this)">上增</a>&nbsp;&nbsp;
		<a href="javascript:;" onClick="removeColumn(this)">删</a>&nbsp;&nbsp;
		<a href="javascript:;" onClick="addAfterColumn(this)">下增</a></td>
	</tr>
</script>
#end
#define js()
<script src="#(res_path)/hplus/js/plugins/art-template/template-web.js"></script>
<script src="#(res_path)/hplus/js/plugins/validate/jquery.validate.min.js"></script>
<script src="#(res_path)/hplus/js/plugins/validate/messages_zh.min.js"></script>
#end
#define jsFunction()
<script>
	function addAfterColumn(obj){
		$(obj).parent().parent().after(template("columnTpl",{}));
	}
	function addBeforeColumn(obj){
		$(obj).parent().parent().before(template("columnTpl",{}));
	}
	function addAppendColumn(){
		$("#column_box").append(template("columnTpl",{}));
	}
	function addPrependColumn(){
		$("#column_box").prepend(template("columnTpl",{}));
	}
	function removeColumn(obj){
		$(obj).parent().parent().remove();
	}
	function loadTable(){
		$.ajax({
			url:"loadTable",
			data:{plugin_id:#(autocodeComponent.plugin_id),tablename:$("input[name='autocodeModel.tablename']").val()},
			dataType:"json",
			success:function(data){
				if(data.result=="success"){
					$.each(data.columnList,function(index,item){
						$("#column_box").prepend(template("columnTpl",{item}));
					});
				}else {
					layer.msg(data.message);
				}
			}
		})
	}
	
</script>
#end
